
program chapter6_4
    implicit none
    complex x,y,z,cg
    real a,b,c,p,heron,area

    x=cmplx(1.5,2.0)
    y=cmplx(4.5,4.5)
    z=cmplx(18.0,10.5)
    cg=cmplx((real(x)+real(y)+real(z))/3,(aimag(x)+aimag(y)+aimag(z))/3)

    print*, 'center of gravity posed at',cg
    print *,'area=',area
    print *,'use heron function defined in this program, the result is area=',heron(x,y,z)

end program

real function heron(x,y,z)
    !using heron's formula to calculate s
    complex x,y,z
    real a,b,c,p
    a=abs(x-y)
    b=abs(y-z)
    c=abs(x-z)
    p=(a+b+c)/2.0
    heron=sqrt(p*(p-a)*(p-b)*(p-c))
end function
